﻿using System.Collections.Generic;
using System.Data;

namespace MedicService.Server.Factory.Generic {
    public abstract class DirectorySimpleFactory<TEntity> : EntityFactory<TEntity> where TEntity : MedicService.Domain.Generic.DirectorySimpleItem {

        protected DirectorySimpleFactory(string tableName) : base(tableName, "title") {}

        protected DirectorySimpleFactory(string tableName, string orderBy) : base(tableName, orderBy) {}

        protected override void FillEntity(TEntity entity, DataRow myDataRow) {
            entity.Id = (int)myDataRow["id"];
            entity.Title = myDataRow["title"] as string;
        }
        
        protected override string GetInsertQuery(TEntity entity) {
            return "INSERT INTO [" + TableName + "]([title])VALUES('" + entity.Title + "'); ";
        }

        protected override string GetUpdateQuery(TEntity entity) {
            return "UPDATE [" + TableName + "] SET title='" + entity.Title + "' WHERE id = " + entity.Id + ";";
        }

    }
}